package com.tensquare.article.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.article.pojo.Article;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 *
 * @author Administrator
 */
public interface ArticleDao extends JpaRepository<Article, String>, JpaSpecificationExecutor<Article> {

    //文章审核,把state状态,修改为1(0：未审核 1：已审核)
    @Query(value = "UPDATE tb_article SET state = ? WHERE id = ?", nativeQuery = true)
    //执行增删改写操作,需要添加此注解
    @Modifying
    void examine(String state, String articleId);

    //文章点赞,把点赞数thumbup在原来的基础上加一,根据文章id进行点赞
    @Query(value = "UPDATE tb_article SET thumbup = thumbup+1 WHERE id = ?", nativeQuery = true)
    @Modifying
    void thumbup(String articleId);
}
